#!/bin/bash

#default
error_sms=13811111111
error_email=un-error@baidu.com
warn_sms=13822222222
warn_email=un-warn@baidu.com
info_sms=13833333333
info_email=un-info@baidu.com

#specific
ckpageview_email="dulin@baidu.com"

idaycproadposview_sms="13811495977"
idaycproadposview_email="liutong01@baidu.com"

###
#
###
function send_sms {
	echo "send sms: $1 $2"
}

function send_email {
	echo "send email: $1 $2"
}

###
#
###
function error {
  MSG=$1
  BIZ_KEY=$2
  SMS_LIST=`get_sms_list error "$BIZ_KEY"`
  EMAIL_LIST=`get_email_list error "$BIZ_KEY"`
  send_sms $SMS_LIST "[error]$MSG"
  send_email $EMAIL_LIST "[error]$MSG"
}

function warn {
  MSG=$1
  BIZ_KEY=$2
  EMAIL_LIST=`get_email_list warn "$BIZ_KEY"`
  send_email $EMAIL_LIST "[warn]$MSG"
}

function info {
  MSG=$1
  BIZ_KEY=$2
  EMAIL_LIST=`get_email_list warn "$BIZ_KEY"`
  send_email $EMAIL_LIST "[info]$MSG"
}

###
#
###
function get_sms_list {
  NOTIFY_LEVEL=$1
  BIZ_KEY=$2
  
  #default list
  SMS_LIST="$NOTIFY_LEVEL"_sms
  SMS_LIST=${!SMS_LIST}
  
  #get specific list if exists
  BIZ_SMS_KEY="$BIZ_KEY"_sms
  if [ -n "$SMS_LIST" ] && [ -n "${!BIZ_SMS_KEY}" ]
  then
  	SMS_LIST=${!BIZ_SMS_KEY}
  fi
  
  echo $SMS_LIST
}

function get_email_list {
  NOTIFY_LEVEL=$1
  BIZ_KEY=$2
  
  #default list
  EMAIL_LIST="$NOTIFY_LEVEL"_email
  EMAIL_LIST=${!EMAIL_LIST}
  
  #get specific list if exists
  BIZ_EMAIL_KEY="$BIZ_KEY"_email
  if [ -n "$EMAIL_LIST" ] && [ -n "${!BIZ_EMAIL_KEY}" ]
  then
  	EMAIL_LIST=${!BIZ_EMAIL_KEY}
  fi
  
  echo $EMAIL_LIST
}
